package edu.neu.ecommerceplatform.controller;


import edu.neu.ecommerceplatform.model.Category;
import edu.neu.ecommerceplatform.service.CategoryService;
import org.apache.coyote.Response;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/category")
public class CategoryController {
    private final CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @GetMapping("/category_id/{id}")
    public ResponseEntity<List<Category>> getCategoryByParentCategoryID(@PathVariable Long id){
        List<Category> categories = categoryService.getCategoryByParentCategoryID(id);

        return ResponseEntity.ok(categories);
    }
    @GetMapping
    public ResponseEntity<List<Category>> getAll(){
        List<Category> categories = categoryService.getAll();

        return ResponseEntity.ok(categories);
    }
}
